/******************************************************************************
* Copyright (C) 2019 ShenZhen Powerdata Information Technology Co.,Ltd
* All Rights Reserved.
* 本软件为***研制。未经本公司正式书面同意，其他任何个人、团体不得使用、
* 复制、修改或发布本软件.
*****************************************************************************/

package com.tudouji.common.utils;

import java.math.BigDecimal;
import java.text.ParseException;

/**
* @Title:
* @ClassName:  BigDecimalUtils
* @Description:
* @author: liukx
* @date:   2019年10月14日 上午11:07:03
* @since   JDK1.8
* @history 2019年10月14日 BigDecimal处理类
*/
public class BigDecimalUtils {

	/**
	 *
	* @Title: sum
	* @Description: 求和
	* @param @param bigs
	* @param @return
	* @return BigDecimal
	* @throws
	 */
  	public static BigDecimal sum(BigDecimal []  bigs){
  		BigDecimal result = BigDecimal.ZERO;
  		for(BigDecimal big:bigs){
  			result = sum(result,big);
  		}
		return  result;

  	}


  	/**
  	 *
  	* @Title: sum
  	* @Description: 求和
  	* @param @param big1
  	* @param @param big2
  	* @param @return
  	* @return BigDecimal
  	* @throws
  	 */
  	public static BigDecimal sum(BigDecimal big1,BigDecimal big2){
  		return big1.add(big2);
  	}


  	/**
  	 *
  	* @Title: sum
  	* @Description: 求和
  	* @param @param big1
  	* @param @param big2
  	* @param @return
  	* @return BigDecimal
  	* @throws
  	 */
  	public static BigDecimal sum(BigDecimal big1,BigDecimal big2,BigDecimal big3,BigDecimal big4){
  		return sum(big1,sum(big2,sum(big4,big3)));
  	}

  	/**
	 *
	* @Title: sum
	* @Description: 求和
	* @param @param bigs
	* @param @return
	* @return BigDecimal
	* @throws
	 */
  	public static BigDecimal multiply(BigDecimal []  bigs){
  		BigDecimal result = BigDecimal.ONE;
  		for(BigDecimal big:bigs){
  			result = multiply(result,big);
  		}
		return  result;

  	}
  	/**
	 * @auther shaodong
	 * @desc 保留两位小数且四舍五入
	 * @Date 14:16 2020/5/25
	 * @Param [big1, big2]
	 * @return java.math.BigDecimal
	 **/
	public static BigDecimal setScale(BigDecimal bd) {
        return bd = bd.setScale(4, BigDecimal.ROUND_HALF_UP);
  	}

	/**
	 * @param @param  big1
	 * @param @param  big2
	 * @param @return
	 * @return BigDecimal
	 * @throws
	 * @Title: multiply
	 * @Description: 乘
	 */
	public static BigDecimal multiply(BigDecimal big1, BigDecimal big2) {
		return big1.multiply(big2);
	}



  	/**
  	 *
  	* @Title: multiply
  	* @Description: 减
  	* @param @param big1
  	* @param @param big2
  	* @param @return
  	* @return BigDecimal
  	* @throws
  	 */
  	public static BigDecimal subtract(BigDecimal big1,BigDecimal big2){
  		return big1.subtract(big2);
  	}


	/**
  	 *
  	* @Title: multiply
  	* @Description: 百分比
  	* @param @param big1
  	* @param @param big2
  	* @param @return
  	* @return BigDecimal
  	* @throws
  	 */
  	public static BigDecimal percentage(BigDecimal big1){
  		return subtract(BigDecimal.ONE, big1.divide(new BigDecimal(100)));
  	}



  	/**
  	 *
  	* @Title: equals
  	* @Description: 是否相等
  	* @param @param contract
  	* @param @param qaForm
  	* @param @return
  	* @return boolean
  	* @throws
  	 */
	public static boolean equals(BigDecimal big1,BigDecimal big2){
		return big1.compareTo(big2) == 0;
	}


	/**
  	 *
  	* @Title: greaterThanZero
  	* @Description: 大于0
  	* @param @param contract
  	* @param @param qaForm
  	* @param @return
  	* @return boolean
  	* @throws
  	 */
	public static boolean greaterThanZero(BigDecimal big1){
		return big1.compareTo(BigDecimal.ZERO) == 1;
	}


	/**
 	 *
 	* @Title: lessThanZero
 	* @Description: 小于0
 	* @param @param contract
 	* @param @param qaForm
 	* @param @return
 	* @return boolean
 	* @throws
 	 */
	public static boolean lessThanZero(BigDecimal big1){
		return big1.compareTo(BigDecimal.ZERO) < 0;
	}


	public static void main(String[] args) {
		try {
			boolean a = DateUtils.compare(DateUtils.getNowDate(), DateUtils.parseDate("2024-05-01 00:00:00" , DateUtils.YYYY_MM_DD_HH_MM_SS));
			System.out.println(a);
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
	}


	/**
  	 *
  	* @Title: isEmpty
  	* @Description: 是否为空
  	* @param @param big1
  	* @param @return
  	* @return boolean
  	* @throws
  	 */
	public static boolean isEmpty(BigDecimal big1){
		return big1 == null;
	}



	/**
  	 *
  	* @Title: isNotEmpty
  	* @Description: 是否不为空
  	* @param @param big1
  	* @param @return
  	* @return boolean
  	* @throws
  	 */
	public static boolean isNotEmpty(BigDecimal big1){
		return !isEmpty(big1);
	}




	/**
	 *
	* @Title: geMax
	* @Description: 取最大
	* @param @param big1
	* @param @param big2
	* @param @return
	* @return BigDecimal
	* @throws
	 */
	public static BigDecimal geMax(BigDecimal big1,BigDecimal big2){
		return big1.compareTo(big2) == 1?big1:big2;
	}


	/**
	 *
	* @Title: geMin
	* @Description: 取最小
	* @param @param big1
	* @param @param big2
	* @param @return
	* @return BigDecimal
	* @throws
	 */
	public static BigDecimal geMin(BigDecimal big1,BigDecimal big2){
		return big1.compareTo(big2) == -1?big1:big2;
	}


	/**
	 *
	* @Title: formatBigDecimal
	* @Description: 格式化BigDecimal，保留两位
	* 				保留格式方式 ：2.226667 --> 2.23
	* 				ROUND_HALF_UP 四合五入
	* @param @param price
	* @param @return
	* @return BigDecimal
	* @throws
	 */
	public static BigDecimal formatBigDecimal(BigDecimal price ,int  count){
		return 	price.setScale(count, BigDecimal.ROUND_HALF_UP );
	}



	 /**
	  *
	 * @Title: unitChange
	 * @Description:
	 * @param @param price
	 * @param @param count
	 * @param @return
	 * @return BigDecimal
	 * @throws
	  */
	public static BigDecimal unitChange(BigDecimal value ,int  hex){

		return multiply(value,new BigDecimal(hex));
	}


	 /**
	  *
	 * @Title: unitChange
	 * @Description:
	 * @param @param price
	 * @param @param count
	 * @param @return
	 * @return BigDecimal
	 * @throws
	  */
	public static BigDecimal kgTolb(BigDecimal value ){

		return value.divide(new BigDecimal(1000)) ;
	}



}
